/**
 * 实体权限服务注册中心
 *
 * @export
 * @class AuthServiceRegister
 */
export class AuthServiceRegister {

    /**
     * 所有实体权限服务Map
     *
     * @protected
     * @type {*}
     * @memberof AuthServiceRegister
     */
    protected allAuthService: Map<string, () => Promise<any>> = new Map();

    /**
     * 已加载实体权限服务Map缓存
     *
     * @protected
     * @type {Map<string, any>}
     * @memberof AuthServiceRegister
     */
    protected serviceCache: Map<string, any> = new Map();

    /**
     * Creates an instance of AuthServiceRegister.
     * @memberof AuthServiceRegister
     */
    constructor() {
        this.init();
    }

    /**
     * 初始化
     *
     * @protected
     * @memberof AuthServiceRegister
     */
    protected init(): void {
                this.allAuthService.set('eamdocument', () => import('@/authservice/eamdocument/eamdocument-auth-service'));
        this.allAuthService.set('eamlocationstatemodel', () => import('@/authservice/eamlocation-state-model/eamlocation-state-model-auth-service'));
        this.allAuthService.set('eamlocationtype', () => import('@/authservice/eamlocation-type/eamlocation-type-auth-service'));
        this.allAuthService.set('eamworkorder', () => import('@/authservice/eamwork-order/eamwork-order-auth-service'));
        this.allAuthService.set('eamlocation', () => import('@/authservice/eamlocation/eamlocation-auth-service'));
        this.allAuthService.set('eammonitorpoint', () => import('@/authservice/eammonitor-point/eammonitor-point-auth-service'));
        this.allAuthService.set('eamassetstate', () => import('@/authservice/eamasset-state/eamasset-state-auth-service'));
        this.allAuthService.set('eamlocationstate', () => import('@/authservice/eamlocation-state/eamlocation-state-auth-service'));
        this.allAuthService.set('eamassettype', () => import('@/authservice/eamasset-type/eamasset-type-auth-service'));
        this.allAuthService.set('eamassetstatemodelline', () => import('@/authservice/eamasset-state-model-line/eamasset-state-model-line-auth-service'));
        this.allAuthService.set('woorigin', () => import('@/authservice/woorigin/woorigin-auth-service'));
        this.allAuthService.set('eamapplytype', () => import('@/authservice/eamapply-type/eamapply-type-auth-service'));
        this.allAuthService.set('eamproduct', () => import('@/authservice/eamproduct/eamproduct-auth-service'));
        this.allAuthService.set('eamservicelevel', () => import('@/authservice/eamservice-level/eamservice-level-auth-service'));
        this.allAuthService.set('eamplancdt', () => import('@/authservice/eamplan-cdt/eamplan-cdt-auth-service'));
        this.allAuthService.set('eamplan', () => import('@/authservice/eamplan/eamplan-auth-service'));
        this.allAuthService.set('eamsparepartspro', () => import('@/authservice/eamspare-parts-pro/eamspare-parts-pro-auth-service'));
        this.allAuthService.set('eamapplystatemodelline', () => import('@/authservice/eamapply-state-model-line/eamapply-state-model-line-auth-service'));
        this.allAuthService.set('eamsparepartsgroup', () => import('@/authservice/eamspare-parts-group/eamspare-parts-group-auth-service'));
        this.allAuthService.set('eamplanline', () => import('@/authservice/eamplan-line/eamplan-line-auth-service'));
        this.allAuthService.set('eamlocationstatemodelline', () => import('@/authservice/eamlocation-state-model-line/eamlocation-state-model-line-auth-service'));
        this.allAuthService.set('eamplanschedule', () => import('@/authservice/eamplan-schedule/eamplan-schedule-auth-service'));
        this.allAuthService.set('eamassetpartsgroup', () => import('@/authservice/eamasset-parts-group/eamasset-parts-group-auth-service'));
        this.allAuthService.set('eamasset', () => import('@/authservice/eamasset/eamasset-auth-service'));
        this.allAuthService.set('eamapplystate', () => import('@/authservice/eamapply-state/eamapply-state-auth-service'));
        this.allAuthService.set('eamapply', () => import('@/authservice/eamapply/eamapply-auth-service'));
        this.allAuthService.set('eamwostate', () => import('@/authservice/eamwostate/eamwostate-auth-service'));
        this.allAuthService.set('eamdocumenttype', () => import('@/authservice/eamdocument-type/eamdocument-type-auth-service'));
        this.allAuthService.set('eamassetstatemodel', () => import('@/authservice/eamasset-state-model/eamasset-state-model-auth-service'));
        this.allAuthService.set('eamwotype', () => import('@/authservice/eamwotype/eamwotype-auth-service'));
    }

    /**
     * 加载实体权限服务
     *
     * @protected
     * @param {string} serviceName
     * @returns {Promise<any>}
     * @memberof AuthServiceRegister
     */
    protected async loadService(serviceName: string): Promise<any> {
        const service = this.allAuthService.get(serviceName);
        if (service) {
            return service();
        }
    }

    /**
     * 获取应用实体权限服务
     *
     * @param {string} name
     * @returns {Promise<any>}
     * @memberof AuthServiceRegister
     */
    public async getService(name: string): Promise<any> {
        if (this.serviceCache.has(name)) {
            return this.serviceCache.get(name);
        }
        const authService: any = await this.loadService(name);
        if (authService && authService.default) {
            const instance: any = new authService.default();
            this.serviceCache.set(name, instance);
            return instance;
        }
    }

}
export const authServiceRegister: AuthServiceRegister = new AuthServiceRegister();